<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调整颜色亮度</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 20px;
            text-align: center;
            color: #333;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        h1 {
            color: #2c3e50;
        }

        .color-display {
            margin: 20px 0;
            padding: 50px;
            border-radius: 8px;
            background-color: hsl(210, 100%, 50%);
            color: white;
            font-size: 20px;
            font-weight: bold;
            transition: background-color 0.3s ease;
        }

        .slider-container {
            margin-top: 20px;
        }

        .slider {
            width: 100%;
            height: 25px;
            background-color: #ddd;
            border-radius: 12px;
            outline: none;
            transition: background-color 0.3s ease;
        }

        .slider:focus {
            background-color: #3498db;
        }

        .value-display {
            font-size: 16px;
            margin-top: 10px;
        }

        .button {
            padding: 10px 20px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin-top: 20px;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }

        .button:hover {
            background-color: #2980b9;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>调整颜色亮度</h1>
        <div class="color-display" id="colorDisplay">HSL(210, 100%, 50%)</div>
        <div class="slider-container">
            <input type="range" id="lightnessSlider" class="slider" min="-50" max="50" value="0">
            <div class="value-display" id="sliderValue">亮度变化: 0</div>
        </div>
        <button class="button" id="resetButton">重置亮度</button>
    </div>

    <script>
        // 调整亮度的函数
        const changeLightness = (delta, hsl) => {
            const [hue, saturation, lightness] = hsl.match(/\d+/g).map(Number);
            const newLightness = Math.max(
                0,
                Math.min(100, lightness + parseFloat(delta))
            );
            return `hsl(${hue},${saturation}%,${newLightness}%)`;
        };

        const colorDisplay = document.getElementById('colorDisplay');
        const lightnessSlider = document.getElementById('lightnessSlider');
        const sliderValue = document.getElementById('sliderValue');
        const resetButton = document.getElementById('resetButton');

        // 初始化颜色
        let currentHSL = "hsl(210, 100%, 50%)"; // 初始颜色值 HSL

        // 更新显示的颜色和亮度
        const updateColor = () => {
            const value = lightnessSlider.value;
            sliderValue.textContent = `亮度变化: ${value}`;
            const newColor = changeLightness(value, currentHSL);
            colorDisplay.style.backgroundColor = newColor;
            colorDisplay.textContent = newColor;
        };

        // 监听滑块变化
        lightnessSlider.addEventListener('input', updateColor);

        // 点击重置按钮重置颜色和亮度
        resetButton.addEventListener('click', () => {
            lightnessSlider.value = 0;
            sliderValue.textContent = `亮度变化: 0`;
            colorDisplay.style.backgroundColor = currentHSL;
            colorDisplay.textContent = currentHSL;
        });

        // 初始更新显示颜色
        updateColor();
    </script>

</body>

</html>